package com.pfzy.lib.net.convert;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * 自定义响应ResponseBody
 */
public class JsonResponseBodyConverter implements Converter<ResponseBody, String> {
    private final Gson gson;
    private final TypeAdapter adapter;
    private boolean isEncrypt;

    /**
     * 构造器
     */
    JsonResponseBodyConverter(Gson gson, TypeAdapter adapter,boolean isEncrypt) {
        this.gson = gson;
        this.adapter = adapter;
        this.isEncrypt = isEncrypt;
    }

    @Override
    public String convert(ResponseBody value) throws IOException {
        //得到请求返回体的内容
        String string = value.string();
        if (isEncrypt) {
//            System.out.println("#解密前@#" + string);
//            try {
//                string = MyAES.aesDecrypt(string);
//            } catch (Exception e) {
//                System.out.println("#解密出错@#" + e.getMessage());
//                string = "";
//            }
//            System.out.println("#解密后@#" + string);
        }
        return string;
    }
}
